<?php

namespace app\after\controller;

use think\Controller;
use think\Loader;
use think\Request;
use think\Session;

class After extends Controller
{





    //登录页面
    public function login()
    {
        return view();
    }

//    执行登录
    public function doLogin()
    {
        $data = input();
//       验证
        $validate = Loader::validate('Admin');
        if (!$validate->scene('login')->check($data)) {
            $this->error($validate->getError());
        }
        //设置token
        $token = \Token::create_token('token');
        Session::set('token', $token);
        $data['token'] = $token;
        $res = \app\after\model\After::login($data);
//        print_r($res);die();
        if (!$res) {
            $this->error('账号或密码有误...', '/after/after/login');
        } else {
            return json(['code' => 200, 'msg' => '登录成功', 'data' => $data]);
        }

    }

//    建立软删除
    public function softDel($id)
    {
        $token = Session::get('token');
        $data = \app\after\model\Show::softDelete($id);
        if ($data) {
            $this->success('删除成功，正在跳转...', '/after/show/show?token=' . $token);
        } else {
            $this->success('删除失败，正在跳转...', '/after/show/show');
        }
    }

//    建立回收站
    public function recycling()
    {

        $data = \app\after\model\Show::recycling();
        $this->assign('data', $data);
        return view();

    }

//    彻底删除
    public function delete($id)
    {
        $token = Session::get('token');
        $data = \app\after\model\Show::deletes($id);
        if ($data) {
            $this->success('删除成功，正在跳转...', 'after/after/recycling?token=' . $token);
        } else {
            $this->success('删除失败，正在跳转...', '/after/after/recycling');
        }
    }

    //详情信息
    public function details($id)
    {
        $res = \app\after\model\Show::details($id);
//       print_r($res);die();
        $this->assign('res', $res);
        return view();
    }

    //恢复
    public function restore($id)
    {
        $res = \app\after\model\Show::restores($id);
        $token = Session::get('token');
        if (!$res) {
            $this->success('恢复成功，正在跳转...', 'after/show/show?token=' . $token);
        } else {
            $this->success('恢复失败，正在跳转...', '/after/show/show');
        }
    }
}
